package cn.ibizlab.odoo.core.odoo_stock.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Istock_location_route;
import cn.ibizlab.odoo.core.odoo_stock.domain.Stock_location_route;
import cn.ibizlab.odoo.core.odoo_stock.filter.Stock_location_routeSearchContext;
import cn.ibizlab.odoo.core.odoo_stock.service.IStock_location_routeService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[库存路线] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Stock_location_routeServiceImpl implements IStock_location_routeService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Istock_location_routeClientService stock_location_routeClientService;

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //stock_location_routeClientService.removeBatch(stock_location_routes) ;

    }

    @Override
    public boolean create(Stock_location_route stock_location_route) {
        boolean bOk = false ;
        Istock_location_route clientModel = this.convert2Model(stock_location_route,null);
        stock_location_routeClientService.create(clientModel) ;
        this.convert2Domain(clientModel,stock_location_route);
        bOk = true ;

        return bOk ;
    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Istock_location_route clientModel = stock_location_routeClientService.createModel();
        clientModel.setId(id);
        stock_location_routeClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void createBatch(List<Stock_location_route> stock_location_routes, int batchSize) {

                        //stock_location_routeClientService.createBatch(stock_location_routes,batchSize) ;

    }

    @Override
    public Stock_location_route get(Integer id) {
        Istock_location_route clientModel = stock_location_routeClientService.createModel();
        clientModel.setId(id);
        stock_location_routeClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Stock_location_route get(Stock_location_route stock_location_route) {
        Stock_location_route retstock_location_route = this.get(stock_location_route.getId()) ;
    	BeanCopier copier=BeanCopier.create(retstock_location_route.getClass(), stock_location_route.getClass(), false);
        copier.copy(retstock_location_route, stock_location_route, null);
        return stock_location_route ;
    }

    @Override
    public void updateBatch(List<Stock_location_route> stock_location_routes, int batchSize) {

        //stock_location_routeClientService.updateBatch(stock_location_routes,batchSize) ;

    }

    @Override
    public boolean update(Stock_location_route stock_location_route) {
        boolean bOk = false ;
        Istock_location_route clientModel = this.convert2Model(stock_location_route,null);
        stock_location_routeClientService.update(clientModel) ;
        this.convert2Domain(clientModel,stock_location_route) ;
        bOk = true;
        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Stock_location_route> searchDefault(Stock_location_routeSearchContext context) {
        List<Stock_location_route> list = new ArrayList<Stock_location_route>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_location_route> clientModelList = stock_location_routeClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_location_route clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_location_route>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据公司查询
     */
    @Override
    public Page<Stock_location_route> selectByOdoo_company(Integer id){
        Stock_location_routeSearchContext context = new Stock_location_routeSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_location_route> list = new ArrayList<Stock_location_route>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_location_route> clientModelList = stock_location_routeClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_location_route clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_location_route>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Stock_location_route> selectByOdoo_create(Integer id){
        Stock_location_routeSearchContext context = new Stock_location_routeSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_location_route> list = new ArrayList<Stock_location_route>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_location_route> clientModelList = stock_location_routeClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_location_route clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_location_route>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Stock_location_route> selectByOdoo_write(Integer id){
        Stock_location_routeSearchContext context = new Stock_location_routeSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_location_route> list = new ArrayList<Stock_location_route>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_location_route> clientModelList = stock_location_routeClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_location_route clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_location_route>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据仓库查询
     */
    @Override
    public Page<Stock_location_route> selectByOdoo_supplied_wh(Integer id){
        Stock_location_routeSearchContext context = new Stock_location_routeSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_location_route> list = new ArrayList<Stock_location_route>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_location_route> clientModelList = stock_location_routeClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_location_route clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_location_route>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据仓库查询
     */
    @Override
    public Page<Stock_location_route> selectByOdoo_supplier_wh(Integer id){
        Stock_location_routeSearchContext context = new Stock_location_routeSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Stock_location_route> list = new ArrayList<Stock_location_route>();
        Page<cn.ibizlab.odoo.core.client.model.Istock_location_route> clientModelList = stock_location_routeClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Istock_location_route clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Stock_location_route>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Istock_location_route convert2Model(Stock_location_route domain , Istock_location_route model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = stock_location_routeClientService.createModel() ;
        }

         if(domain.getSale_selectableDirtyFlag())
            model.setSale_selectable(domain.getSale_selectable());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getProduct_idsDirtyFlag())
            model.setProduct_ids(domain.getProduct_ids());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getCateg_idsDirtyFlag())
            model.setCateg_ids(domain.getCateg_ids());
         if(domain.getWarehouse_selectableDirtyFlag())
            model.setWarehouse_selectable(domain.getWarehouse_selectable());
         if(domain.getSequenceDirtyFlag())
            model.setSequence(domain.getSequence());
         if(domain.getRule_idsDirtyFlag())
            model.setRule_ids(domain.getRule_ids());
         if(domain.getProduct_selectableDirtyFlag())
            model.setProduct_selectable(domain.getProduct_selectable());
         if(domain.getActiveDirtyFlag())
            model.setActive(domain.getActive());
         if(domain.getProduct_categ_selectableDirtyFlag())
            model.setProduct_categ_selectable(domain.getProduct_categ_selectable());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getWarehouse_idsDirtyFlag())
            model.setWarehouse_ids(domain.getWarehouse_ids());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getSupplied_wh_id_textDirtyFlag())
            model.setSupplied_wh_id_text(domain.getSupplied_wh_id_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getSupplier_wh_id_textDirtyFlag())
            model.setSupplier_wh_id_text(domain.getSupplier_wh_id_text());
         if(domain.getCompany_id_textDirtyFlag())
            model.setCompany_id_text(domain.getCompany_id_text());
         if(domain.getCompany_idDirtyFlag())
            model.setCompany_id(domain.getCompany_id());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getSupplier_wh_idDirtyFlag())
            model.setSupplier_wh_id(domain.getSupplier_wh_id());
         if(domain.getSupplied_wh_idDirtyFlag())
            model.setSupplied_wh_id(domain.getSupplied_wh_id());
        return model ;
    }

    public Stock_location_route convert2Domain( Istock_location_route model ,Stock_location_route domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Stock_location_route();
        }

        if(model.getSale_selectableDirtyFlag())
            domain.setSale_selectable(model.getSale_selectable());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getProduct_idsDirtyFlag())
            domain.setProduct_ids(model.getProduct_ids());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getCateg_idsDirtyFlag())
            domain.setCateg_ids(model.getCateg_ids());
        if(model.getWarehouse_selectableDirtyFlag())
            domain.setWarehouse_selectable(model.getWarehouse_selectable());
        if(model.getSequenceDirtyFlag())
            domain.setSequence(model.getSequence());
        if(model.getRule_idsDirtyFlag())
            domain.setRule_ids(model.getRule_ids());
        if(model.getProduct_selectableDirtyFlag())
            domain.setProduct_selectable(model.getProduct_selectable());
        if(model.getActiveDirtyFlag())
            domain.setActive(model.getActive());
        if(model.getProduct_categ_selectableDirtyFlag())
            domain.setProduct_categ_selectable(model.getProduct_categ_selectable());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getWarehouse_idsDirtyFlag())
            domain.setWarehouse_ids(model.getWarehouse_ids());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getSupplied_wh_id_textDirtyFlag())
            domain.setSupplied_wh_id_text(model.getSupplied_wh_id_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getSupplier_wh_id_textDirtyFlag())
            domain.setSupplier_wh_id_text(model.getSupplier_wh_id_text());
        if(model.getCompany_id_textDirtyFlag())
            domain.setCompany_id_text(model.getCompany_id_text());
        if(model.getCompany_idDirtyFlag())
            domain.setCompany_id(model.getCompany_id());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getSupplier_wh_idDirtyFlag())
            domain.setSupplier_wh_id(model.getSupplier_wh_id());
        if(model.getSupplied_wh_idDirtyFlag())
            domain.setSupplied_wh_id(model.getSupplied_wh_id());
        return domain ;
    }


}
